<%inherit file="base.html"/>

<%def name="head()">
<script>
    function deletePolicy(policy_id)
    {
        if(confirm("确认删除吗？"))
        {
            params = {policy_id: policy_id, _xsrf: '${handler.xsrf_token}'};
            $.post("/oss/delete", params, function (data) {
                if (data.code > 0) {
                    alert(data.msg)
                    return false;
                }
                else {
                    window.location.href = "/oss";
                }
            }, "json");
        }
    }

    function activateOss(oss_id)
    {
        if(confirm("同一时间只有一台服务器能处于活主机状态,确认设置主服务器吗？"))
        {
            window.location.href = "/oss/activate?oss_id="+oss_id;
        }
    }
</script>
<style type="text/css">
    .break-all {
        word-break: break-all; /*必須*/
    }
</style>
</%def>

<%def name="body()">
<section class="content">
    <div class="box box-primary">
        <div class="box-header">
            <i class="fa fa-sitemap"></i>
            <h3 class="box-title">OSS服务器列表</h3>
        </div>
        <div class="box-body">
            <div class="container">
                % if permit.match(current_user.username,'/oss/add'):
                <div class="pull-right bottom10">
                     <a href="/oss/add" class="btn btn-sm btn-info">增加OSS服务器</a>
                </div>
                % endif

                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>名称</th>
                            <th>认证地址</th>
                            <th>记账地址</th>
                            <th>类型</th>
                            <th>共享密钥</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        % for item in oss_server_list:
                            <tr>
                                <td width="10%">${item.name}</td>
                                <td width="22%" class="break-all">${item.auth_url}</td>
                                <td width="23%" class="break-all">${item.acct_url}</td>
                                <td width="5%">${serv_types[item.serv_type]}</td>
                                <td width="15%" class="break-all">${item.secret}</td>
                                <td width="5%">${utils.is_connect(item.last_check) and '<span \
                                       class="label label-success">连接</span>' or '<span class="label label-default">失联</span>'}
                                </td>
                                <td width="20%">
                                    % if permit.match(current_user.username,'/oss/update'):
                                    <a class="opt-btn btn-default" href="/oss/update?oss_id=${item.id}">修改</a>
                                    % endif
                                    % if permit.match(current_user.username,'/oss/delete'):
                                    <a class="opt-btn btn-default" href="javascript:deleteOss('${item.id}')">删除</a>
                                    % endif
                                    % if permit.match(current_user.username,'/oss/activate'):
                                    <a class="opt-btn btn-default" href="javascript:activateOss('${item.id}')">设为主机</a>
                                    % endif
                                </td>
                            </tr>
                        % endfor
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>
</%def>